﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using UniversityStudentManagemnetSystem.DAO.DAL;
using UniversityStudentManagemnetSystem.DAO.DAL.Gateway;
using UniversityStudentManagemnetSystem.DAO.Gateway;

namespace UniversityStudentManagemnetSystem.BLL
{
    public class CourseAssignManager:Manager
    {
        CourseAssignGateway  courseAssignGateway;

        public CourseAssignManager()
        {
            courseAssignGateway = new CourseAssignGateway();
        }

        public object GetCourseOrCourseTeacher(int selectedCourseId)
        {
            DataTable teacherTable = courseAssignGateway.GetTeacherOf(selectedCourseId);

            Teacher aTeacher;
            Course aCourse;
            if (teacherTable.Rows.Count == (int)Rows.oneRowCounted)
            {
                aTeacher = new Teacher();
                aTeacher.TeacherName = teacherTable.Rows[0]["Name"].ToString();
                aTeacher.Department.Name = teacherTable.Rows[0]["Department"].ToString();
                aTeacher.Designation.DesignationName = teacherTable.Rows[0]["Designation"].ToString();

                return aTeacher;
            }
            else
            {
                DataTable studentTable = courseAssignGateway.GetAllOf(selectedCourseId);
                aCourse = new Course();

                aCourse.CourseName = studentTable.Rows[0]["CourseName"].ToString();
                aCourse.Credit = studentTable.Rows[0]["Credit"].ToString();

                return aCourse;
            }
        }

        public string SetCourseTo(Teacher aTeacher)
        {
            courseAssignGateway.SetCourseTo(aTeacher);
            return "Course Added To, " + aTeacher.TeacherName+" ,Successfully.";
        }
    }
}